Repository navigation
PDF thumbnail example in one pdf -> jpg call; README pdf-to-jpg snippet compiles and uses real parameters - #21
Merged
Merged
Conversation
…-jpg snippet examples/thumbnail converted page 1 to JPG, then scaled it with a second jpg -> jpg conversion. One pdf -> jpg call with pagerange 1 and imageheight 300 makes the thumbnail (231x300 for assets/test.pdf). The result variable is jpgRes; extractRes is gone. The file now ends with a newline (gofmt). The README "Additional conversion parameters" snippet used an undefined extractRes as its file and passed scaleimage and scaleproportions, which pdf -> jpg does not have. It now converts test.pdf and turns page 1 into a JPG that fits inside 300x300: pagerange, imagewidth, imageheight and fittosize. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues block the PDF thumbnail simplification and README example corrections.
No open issues 🎉
What changed in this PR
Simplifies PDF thumbnail generation and corrects the README’s PDF-to-JPG example to use supported conversion parameters.
Changes:
- Generates the thumbnail in one PDF-to-JPG conversion, preserving the page’s aspect ratio at 300 pixels high.
- Replaces the README’s undefined result reference with a file input and parameters that fit page 1 within 300×300 pixels.
| File | Description |
|---|---|
README.md |
Corrects the input and sizing parameters in the PDF-to-JPG snippet. |
examples/thumbnail/main.go |
Removes the second conversion and adds a final newline. |
Review effort: Balanced
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
examples/thumbnail/main.gomade the thumbnail in two conversions:pdf -> jpgwithpagerange1, thenjpg -> jpgwithscaleimage,scaleproportionsandimageheight300 to shrink the page.pdf -> jpgcan size the image itself, so the second conversion only costs time and a conversion.extractRes. It also passedscaleimageandscaleproportionstopdf -> jpg. Neither is a pdf-to-jpg parameter (spec), and the API ignores them silently. They exist only on jpg-to-jpg (spec).Change
examples/thumbnail/main.go: onepdf -> jpgcall withpagerange1 andimageheight300; the width follows the page's aspect ratio.extractResis gone and the one result isjpgRes. The file now ends with a newline, sogofmt -lno longer lists it.test.pdf(param.NewPath) and turns page 1 into a JPG that fits inside 300x300, withpagerange,imagewidth,imageheightandfittosize. Withoutfittosize, pdf-to-jpg applies the width and lets the height grow (300x388 for a US Letter page).Verification
Docker
golang:1.27(Go 1.27.3), from the repository root, against the production API on 2026-11-09.gofmt -l examples/thumbnail/main.goprints nothing;go vet ./...andgo build ./...pass./tmp/thumbnail.jpgis 231x300 px, 8,858 bytes, from one conversion. The example onmain(606cbee) made a 232x300 px, 9,117-byte thumbnail from two conversions.The README snippet, pasted verbatim into a
mainthat sets the token, then printsjpgRes.Cost()and callsjpgRes.ToPath("/out"), run in a folder holdingtest.pdf(a copy ofassets/test.pdf):test.jpgis byte-identical to the thumbnail above (231x300 px, 8,858 bytes).Only an example and the README change, not the module, so there is no CHANGELOG entry.
The same README fix for Java is in ConvertAPI/convertapi-library-java#57 and for .NET in ConvertAPI/convertapi-library-dotnet#83. Seen, not changed: nine other examples also lack a final newline (
gofmt -l .lists them).🤖 Generated with Claude Code